package com.pubinfo.passbook.common.service.master.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pubinfo.passbook.common.entity.TRuleChargeGenera;
import com.pubinfo.passbook.common.entity.TRuleReimbursable;
import com.pubinfo.passbook.common.mapper.TRuleChargeGeneraMapper;
import com.pubinfo.passbook.common.mapper.TRuleReimbursableMapper;
import com.pubinfo.passbook.common.model.dto.rule.RuleReimbursableParam;
import com.pubinfo.passbook.common.model.vo.base.JsonResult;
import com.pubinfo.passbook.common.service.master.TRuleReimbursableService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 *
 */
@Service
@Slf4j
public class TRuleReimbursableServiceImpl extends ServiceImpl<TRuleReimbursableMapper, TRuleReimbursable>
    implements TRuleReimbursableService {
  
  @Resource
  private TRuleChargeGeneraMapper generaMapper;
  
  @Override
  public IPage<TRuleReimbursable> selectReimbursable(RuleReimbursableParam param) {
    IPage<TRuleReimbursable> iPage = page(param.getPage("create_time"));
    return this.baseMapper.selectReimbursable(iPage, param);
  }
  
  @Override
  public JsonResult<String> deleteReimbursable(String reimbursableId) {
    this.baseMapper.deleteRoleReimbursable(reimbursableId);
    this.baseMapper.deleteById(reimbursableId);
    return JsonResult.success("删除成功");
  }
  
  @Override
  public JsonResult<String> saveReimbursable(TRuleReimbursable reimbursable) {
    TRuleChargeGenera tRuleChargeGenera = generaMapper.selectById(reimbursable.getChargeGeneraId());
    if (tRuleChargeGenera == null)
      return JsonResult.error("收费大类id不存在");
    this.baseMapper.insert(reimbursable);
    return JsonResult.success("保存成功");
  }
  
  @Override
  public JsonResult<String> updateReimbursable(TRuleReimbursable reimbursable) {
    TRuleChargeGenera tRuleChargeGenera = generaMapper.selectById(reimbursable.getChargeGeneraId());
    if (tRuleChargeGenera == null)
      return JsonResult.error("收费大类id不存在");
    this.baseMapper.updateById(reimbursable);
    return JsonResult.success("更新成功");
  }
}




